﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using AutoFacUtils;
using CashFlow.Admin.Service;

namespace CashFlow.Admin.Filters
{
    public class AdminFilterAttribute : ActionFilterAttribute
    {
        private IAdminService GetAdminService() { return AutoFacHelper.Get<IAdminService>(); }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var service = GetAdminService();
            if (!service.IsAdministrator())
            {
                var context = filterContext.HttpContext;
                context.Response.StatusCode = 403;
                filterContext.Result = new ContentResult
                {
                    Content = "403"
                };
            }
        }
    }
}